version 14.1
set more off

***************************************************************************************************
*THIS FILE PRODUCES TABLE II OF SLEMROD-REHMAN-WASEEM-2020, RESTAT
***************************************************************************************************

*--------------------------
* MAIN REGRESSION 
*--------------------------

/* COLUMN 1 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed.dta", clear
#d					;
matrix 			input table=(0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0,0,0,0);
#d					cr
bys				regno:egen namefreq=min(name_count_v2)
g					treat=namefreq<=10
drop				if namefreq>10 & namefreq<=40
local				j=1
keep				regno year treat
g					one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g					lnfilers=log(nfilers)
g					nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g					after=year>=2012
g					treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local				i=1
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
local				j=`j'+1

/* COLUMN 2 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed.dta", clear
bys				regno:egen namefreq=min(name_count_v2)
g					treat=namefreq<=20
drop				if namefreq>20 & namefreq<=40
keep				regno year treat
g					one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g					lnfilers=log(nfilers)
g					nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g					after=year>=2012
g					treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local				i=1
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
local				j=`j'+1

/* COLUMN 3 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed.dta", clear
bys				regno:egen namefreq=min(name_count_v2)
g					treat=namefreq<=30
drop				if namefreq>30 & namefreq<=40
keep				regno year treat
g					one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g					lnfilers=log(nfilers)
g					nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g					after=year>=2012
g					treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local				i=1
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
local				j=`j'+1

/* COLUMN 4 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed.dta", clear
bys				regno:egen namefreq=min(name_count_v2)
g					treat=namefreq<=40
keep				regno year treat
g					one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g					lnfilers=log(nfilers)
g					nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g					after=year>=2012
g					treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local				i=1
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
local				j=`j'+1

/* COLUMN 5 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed.dta", clear
bys				regno:egen namefreq=min(name_count_v2)
qui				sum namefreq,d
g					treat=namefreq<=r(p50)
keep				regno year treat
g					one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g					lnfilers=log(nfilers)
g					nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g					after=year>=2012
g					treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local				i=1
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
local				j=`j'+1

/* COLUMN 6 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed.dta", clear
bys				regno:egen namefreq=min(name_count_v2)
qui            sum namefreq, d
g              treat=namefreq<=r(p25)
drop           if namefreq>r(p25) & namefreq<=r(p75)
keep				regno year treat
g					one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g					lnfilers=log(nfilers)
g					nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g					after=year>=2012
g					treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local				i=1
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
local				j=`j'+1

/* COLUMN 7 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed.dta", clear
bys				regno:egen namefreq=min(name_count_v2)
qui            sum namefreq, d
g              treat=namefreq<=r(p10)
drop           if namefreq>r(p10) & namefreq<=r(p90)
keep				regno year treat
g					one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g					lnfilers=log(nfilers)
g					nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g					after=year>=2012
g					treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local				i=1
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]

*--------------------------
* PLACEBO REGRESSION 
*--------------------------

/* COLUMN 1 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed.dta", clear
bys				regno:egen namefreq=min(name_count_v2)
g					treat=namefreq<=10
drop				if namefreq>10 & namefreq<=40
local				j=1
keep				regno year treat
keep				if year<=2011
g					one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g					lnfilers=log(nfilers)
g					nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g					after=year>=2010
g					treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local				i=3
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
local				j=`j'+1

/* COLUMN 2 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed.dta", clear
bys				regno:egen namefreq=min(name_count_v2)
g					treat=namefreq<=20
drop				if namefreq>20 & namefreq<=40
keep				regno year treat
keep				if year<=2011
g					one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g					lnfilers=log(nfilers)
g					nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g					after=year>=2010
g					treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local				i=3
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
local				j=`j'+1

/* COLUMN 3 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed.dta", clear
bys				regno:egen namefreq=min(name_count_v2)
g					treat=namefreq<=30
drop				if namefreq>30 & namefreq<=40
keep				regno year treat
keep				if year<=2011
g					one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g					lnfilers=log(nfilers)
g					nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g					after=year>=2010
g					treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local				i=3
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
local				j=`j'+1

/* COLUMN 4 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed.dta", clear
bys				regno:egen namefreq=min(name_count_v2)
g					treat=namefreq<=40
keep				regno year treat
keep				if year<=2011
g					one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g					lnfilers=log(nfilers)
g					nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g					after=year>=2010
g					treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local				i=3
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
local				j=`j'+1

/* COLUMN 5 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed.dta", clear
bys				regno:egen namefreq=min(name_count_v2)
qui				sum namefreq,d
g					treat=namefreq<=r(p50)
keep				regno year treat
keep				if year<=2011
g					one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g					lnfilers=log(nfilers)
g					nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g					after=year>=2010
g					treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local				i=3
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
local				j=`j'+1

/* COLUMN 6 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed.dta", clear
bys				regno:egen namefreq=min(name_count_v2)
qui            sum namefreq, d
g              treat=namefreq<=r(p25)
drop           if namefreq>r(p25) & namefreq<=r(p75)
keep				regno year treat
keep				if year<=2011
g					one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g					lnfilers=log(nfilers)
g					nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g					after=year>=2010
g					treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local				i=3
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]
local				j=`j'+1

/* COLUMN 7 */

use				"$project_data\ITRM_Dislo_Unique_SelfEmployed.dta", clear
bys				regno:egen namefreq=min(name_count_v2)
qui            sum namefreq, d
g              treat=namefreq<=r(p10)
drop           if namefreq>r(p10) & namefreq<=r(p90)
keep				regno year treat
keep				if year<=2011
g					one=1
bys				year treat:egen nfilers=sum(one)
duplicates		drop year treat, force
g					lnfilers=log(nfilers)
g					nfnormalized=0
qui				sum lnfilers if treat==1 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==1
qui				sum lnfilers if treat==0 & year==2006
replace			nfnormalized=lnfilers/r(mean) if treat==0
g					after=year>=2010
g					treat_after=treat*after
qui				reg nfnormalized i.year treat treat_after
local				i=3
matrix			table[`i',`j']=_b[treat_after]
matrix 			table[`i'+1,`j']=_se[treat_after]

/* FORMATTING THE TABLE */ 

svmat 			table
keep				tab*
drop				table8-table12
keep				if _n<=4
g					c11=""
replace			c11="treat $\times$ after" in 1
replace			c11="treat $\times$ after" in 3
forvalues 		c=1/7 {
g					c`c'=string(table`c',"%9.4f")
}
foreach			r in 2 4 {
forvalues		c=1/7 {
replace			c`c'="("+string(table`c',"%9.4f")+")" in `r'
}
}
forvalues		s=1/10 {
g					s`s'="&"
}
g					l="\\"
foreach			r in 2 4 {
replace			l="\\\\" in `r'
}
order				c11 s1 c1 s2 c2 s3 c3 s4 c4 s5 c5 s6 c6 s7 c7 l
browse			c11 s1 c1 s2 c2 s3 c3 s4 c4 s5 c5 s6 c6 s7 c7 l
